import multer from "multer";
import feifanc from "../../util/feifanc";
import path from "path";
import rou from "../../util/rou";

export const storage = multer.diskStorage({
  destination: (req, file, cd) => {
    cd(null, path.resolve(__dirname, "../../public/img"));
  },
  filename: (req, file, cd) => {
    const filename =
      feifanc.date("all") + "-" + rou.rou(6) + path.extname(file.originalname);
    req.query.fileurl = "/img/" + filename;
    cd(null, filename);
  },
});
